<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>供应商</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <script src="../../../../res/js/jquery-3.4.1.min.js" charset="utf-8"></script>
    <script src="../../../../res/js/login_common.js" charset="utf-8"></script>
    <script src="../../../../res/layui/layui.js" charset="utf-8"></script>
    <script src="../../../../res/js/Tools.js"></script>
    <link rel="stylesheet" href="../../../../res/layui/css/layui.css" media="all">
</head>

<body>
<form class="layui-form layui-form-pane" id="formDId" action="" method="post" enctype="multipart/form-data">
    <input type="hidden" name="pkSupplierId" id ="pkSupplierId" />

    <div class="layui-form-item">
        <label class="layui-form-label">供应商名称</label>
        <div class="layui-input-block">
            <input type="text" name="supplierName" id = "supplierName" autocomplete="off" lay-verify="required"
                   class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">供应商类型</label>
        <div class="layui-input-block">
            <div id="supplierTypeId" class="xm-select-demo"></div>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">成立日期</label>
        <div class="layui-input-block">
            <input type="text" name="supplierRegisterDate" id = "supplierRegisterDate" autocomplete="off"
                   class="layui-input" lay-verify="date">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">供应商编码</label>
        <div class="layui-input-block">
            <input type="text" name="supplierCode" id = "supplierCode" autocomplete="off" lay-verify="required"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">公司地址</label>
        <div class="layui-input-block">
            <input type="text" name="supplierSite" id = "supplierSite" autocomplete="off" lay-verify="required"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">法人代表</label>
        <div class="layui-input-block">
            <input type="text" name="supplierCorporate" id = "supplierCorporate" autocomplete="off" lay-verify="required"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">营业执照注册号</label>
        <div class="layui-input-block">
            <input type="text" name="supplierBusinessRegister" id = "supplierBusinessRegister" autocomplete="off" lay-verify="required"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">注册资金</label>
        <div class="layui-input-block">
            <input type="text" name="supplierCapital" id = "supplierCapital" autocomplete="off" lay-verify="required"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">组织机构代码</label>
        <div class="layui-input-block">
            <input type="text" name="supplierOrganizationCode" id = "supplierOrganizationCode" autocomplete="off" lay-verify="required"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">市场主体类型</label>
        <div class="layui-input-block">
            <input type="text" name="supplierGenre" id = "supplierGenre" autocomplete="off" lay-verify="required"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">上级母公司</label>
        <div class="layui-input-block">
            <input type="text" name="supplierSuperior" id = "supplierSuperior" autocomplete="off" lay-verify="required"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">公司性质</label>
        <div class="layui-input-block">
            <input type="text" name="supplierNature" id = "supplierNature" autocomplete="off" lay-verify="required"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">纳税人识别号</label>
        <div class="layui-input-block">
            <input type="text" name="supplierInit" id = "supplierInit" autocomplete="off" lay-verify="required"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">户名</label>
        <div class="layui-input-block">
            <input type="text" name="supplierUsername" id = "supplierUsername" autocomplete="off" lay-verify="required"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">开户行</label>
        <div class="layui-input-block">
            <input type="text" name="supplierBank" id = "supplierBank" autocomplete="off" lay-verify="required"
                   class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">银行账号</label>
        <div class="layui-input-block">
            <input type="text" name="supplierBankId" id = "supplierBankId" autocomplete="off" lay-verify="number"
                   class="layui-input">
        </div>
    </div>


    <div class="layui-form-item">
        <label class="layui-form-label">员工数量</label>
        <div class="layui-input-block">
            <input type="text" name="supplierPersonnelNumber" id = "supplierPersonnelNumber" autocomplete="off" lay-verify="number"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">营业场地面积</label>
        <div class="layui-input-block">
            <input type="text" name="supplierArea" id = "supplierArea" autocomplete="off" lay-verify="required"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">经营期限</label>
        <div class="layui-input-block">
            <input type="text" name="supplierDeadline" id = "supplierDeadline" autocomplete="off" lay-verify="required"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">最新年检</label>
        <div class="layui-input-block">
            <input type="text" name="supplierAnnual" id = "supplierAnnual" autocomplete="off" lay-verify="required"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">经营范围</label>
        <div class="layui-input-block">
            <input type="text" name="supplierScope" id = "supplierScope" autocomplete="off" lay-verify="required"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">不良纳税记录</label>
        <div class="layui-input-block">
            <input type="text" name="supplierBadRecord" id = "supplierBadRecord" autocomplete="off" lay-verify="required"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">联系人1</label>
        <div class="layui-input-block">
            <input type="text" name="supplierContactsOne" id = "supplierContactsOne" autocomplete="off" lay-verify="required"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">联系人1职位</label>
        <div class="layui-input-block">
            <input type="text" name="supplierContactsOnePost" id = "supplierContactsOnePost" autocomplete="off" lay-verify="required"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">联系电话1</label>
        <div class="layui-input-block">
            <input type="text" name="supplierContactsOnePhone" id = "supplierContactsOnePhone" autocomplete="off" lay-verify="phone"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">联系人2</label>
        <div class="layui-input-block">
            <input type="text" name="supplierContactsTwo" id = "supplierContactsTwo" autocomplete="off" lay-verify="required"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">联系人2职位</label>
        <div class="layui-input-block">
            <input type="text" name="supplierContactsTwoPost" id = "supplierContactsTwoPost" autocomplete="off" lay-verify="required"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">联系电话2</label>
        <div class="layui-input-block">
            <input type="text" name="supplierContactsTwoPhone" id = "supplierContactsTwoPhone" autocomplete="off" lay-verify="phone"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block" id="flows">
            <input type="button" id="demo3" class="layui-btn layui-btn-primary" value="取消">
        </div>
    </div>
</form>
<script>
    layui.use(['form', 'laydate','upload'], function () {
        var form = layui.form
            , laydate = layui.laydate;
        var $ = layui.jquery
            ,upload = layui.upload;

        //只出现确定按钮
        laydate.render({
            elem: '#supplierRegisterDate'
            , btns: ['confirm']
        });

        var id =getQueryString("pkSupplierId");
        var supplierTypeId;
        var show = getQueryString("show");
        if(id){
            var url=getRootPath()+"OaSupplierAction/findById/"+id;
            var data=getAjaxById(url);
            supplierTypeId = data.data.supplierTypeId;
            $("#pkSupplierId").val(data.data.pkSupplierId);
            $("#supplierName").val(data.data.supplierName);
            $("#supplierTypeId").val(data.data.supplierTypeId);
            $("#supplierRegisterDate").val(dateFormat('yyyy-MM-dd',new Date(data.data.supplierRegisterDate)));
            $("#supplierCode").val(data.data.supplierCode);
            $("#supplierSite").val(data.data.supplierSite);
            $("#supplierCorporate").val(data.data.supplierCorporate);
            $("#supplierCapital").val(data.data.supplierCapital);
            $("#supplierBusinessRegister").val(data.data.supplierBusinessRegister);
            $("#supplierOrganizationCode").val(data.data.supplierOrganizationCode);
            $("#supplierGenre").val(data.data.supplierGenre);
            $("#supplierSuperior").val(data.data.supplierSuperior);
            $("#supplierNature").val(data.data.supplierNature);
            $("#supplierInit").val(data.data.supplierInit);
            $("#supplierUsername").val(data.data.supplierUsername);
            $("#supplierBank").val(data.data.supplierBank);
            $("#supplierBankId").val(data.data.supplierBankId);
            $("#supplierPersonnelNumber").val(data.data.supplierPersonnelNumber);
            $("#supplierDeadline").val(data.data.supplierDeadline);
            $("#supplierArea").val(data.data.supplierArea);
            $("#supplierAnnual").val(data.data.supplierAnnual);
            $("#supplierScope").val(data.data.supplierScope);
            $("#supplierBadRecord").val(data.data.supplierBadRecord);
            $("#supplierContactsOne").val(data.data.supplierContactsOne);
            $("#supplierContactsOnePost").val(data.data.supplierContactsOnePost);
            $("#supplierContactsOnePhone").val(data.data.supplierContactsOnePhone);
            $("#supplierContactsTwo").val(data.data.supplierContactsTwo);
            $("#supplierContactsTwoPost").val(data.data.supplierContactsTwoPost);
            $("#supplierContactsTwoPhone").val(data.data.supplierContactsTwoPhone);
        }


        layui.config({
            //引入扩展文件库
            base: getRootPath()+'res/layui/dist/'
        }).extend({
            //引入对应的文件名
            xmSelect: 'xm-select'
            //拿到对应的文件模块
        }).use(['xmSelect'], function(){
            //对于模块赋值使用
            var xmSelect = layui.xmSelect;
            //渲染多选
            pkJurisdictionId = xmSelect.render({
                el: '#supplierTypeId',
                radio: true,
                layVerify: 'required',
                tree: {
                    show: true,
                    strict: false,
                    expandedKeys: [ -1 ],
                },
                height: 'auto',
                data: loadOaClientType(supplierTypeId,show)
            })

        });
        function loadOaClientType(id,show){
            let url = getRootPath()+"OaSupplierTypeAction/loadOaSupplierType";
            let data = {
                id : id, //需要操作的数据
                show:'2'
            };
            let res = getAjax(url,data);
            if(res){
                return res;
            }else{
                return [];
            }

        }


        //监听起草提交
        form.on('submit(demo1)', function (data) {

            console.info(data.field);
            // 单击之后提交按钮不可选,防止重复提交
            var DISABLED = 'layui-btn-disabled';
            // 增加样式
            $('.site-demo-active').addClass(DISABLED);
            // 增加属性
            $('.site-demo-active').attr('disabled', 'disabled');
            var formData = new FormData(document.getElementById("formDId"));
            console.log(formData)
            let res = postAjaxFile(getRootPath() + "OaSupplierAction/updateOrAdd", formData);
            if (res.code === 1) {
                layer.msg('新增成功3秒后关闭当前窗口', {icon: 1});
                setTimeout(function () {
                    formClose();
                }, 3000);
                setTimeout(function () {
                    parent.layui.table.reload('test');//刷新父页面
                    const index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                    parent.layer.close(index);
                }, 3000);
                //window.location.reload();//刷新页面
            } else if (res.code === 500) {
                error('500');
            } else {
                layer.msg("新增失败");
            }
            return false;
        });

        $("#demo3").on("click", function () {
            //询问框
            layer.confirm('是否关闭该页面？', {
                btn: ['是的', '取消'] //按钮
            }, function () {
                formClose();
                parent.layui.table.reload('test');//刷新父页面
                //window.parent.location.reload();//刷新父页面
                const index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.close(index);
            });
        });
    });


</script>

</body>
</html>